package cn.autoOffice.controller;
/*
 *功能说明：收入支出控制层
 *@author 皮永浪
 *@Date 2023/3/29 11:06
 */

import cn.autoOffice.bean.pojo.FinancialReportDetail;
import cn.autoOffice.bean.vo.Result;
import cn.autoOffice.service.FinancialReportDetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("FinancialReportDetail")
public class FinancialReportDetailController {

    @Autowired
    private FinancialReportDetailService financialReportDetailService;

    //查询所有的收入信息
    @PostMapping("allFinancial/{pageNo}/{pageSize}")
    // @RequiresRoles("financeUser")
    public Result<PageInfo<FinancialReportDetail>> getAllFinancial(@PathVariable Integer pageNo,@PathVariable Integer pageSize){
        PageHelper.startPage(pageNo,pageSize);
        List<FinancialReportDetail> financialReportDetails = financialReportDetailService.findAllFinancialReportDetail();
        PageInfo pageInfo = new PageInfo(financialReportDetails);
        System.out.println("====" + pageInfo.getTotal());
        return Result.success(pageInfo);
    }

    //添加收入信息信息
    @PostMapping("AddFinancial")
    @ResponseBody
    // @RequiresRoles("financeUser")
    public String addFinancialReportDetail(@RequestBody FinancialReportDetail financialReportDetail){
        boolean i = financialReportDetailService.addFinancialReportDetail(financialReportDetail);
        if (i){
            return "0007:收入信息添加成功";
        }else {
            return "0008:收入信息添加失败";
        }
    }
}
